package com.yugao.fintech.antelope.pay.mch.controller;

import com.yugao.fintech.antelope.pay.common.service.MchPayPassageService;
import com.yugao.fintech.antelope.pay.model.rqrs.MchPayPassageConfigQL;
import com.yugao.fintech.antelope.pay.model.rqrs.MchPayPassageRQ;
import com.yugao.fintech.antelope.pay.model.rqrs.MchPayPassageRS;
import com.yugao.fintech.antelope.base.ram.ActionType;
import com.yugao.fintech.antelope.base.ram.RamResource;
import com.yugao.fintech.framework.assistant.utils.exception.BizException;
import com.yugao.fintech.framework.core.response.Resp;

import java.util.List;

/**
 * 商户支付通道配置类
 */
@RestController
@RequestMapping("/mch/payPassage")
public class MchPayPassageConfigController {
    @Autowired
    private MchPayPassageService mchPayPassageService;

    @GetMapping("/list")
    @RamResource(action = "pay:mchPayPassage:list", name = "查询商户支付通道配置列表", type = ActionType.READ)
    public Resp<List<MchPayPassageRS>> list(MchPayPassageConfigQL query) {
        List<MchPayPassageRS> resp = mchPayPassageService.listPayPassage(query);
        return Resp.ok(resp);
    }

    @GetMapping("/get")
    @RamResource(action = "pay:mchPayPassage:get", name = "查询商户支付通道配置详情", type = ActionType.READ)
    public Resp<MchPayPassageRS> get(@RequestParam(value = "id", required = false) Long payPassageId) {
        MchPayPassageRS resp = mchPayPassageService.getPayPassage(payPassageId);
        return Resp.ok(resp);
    }

    @DeleteMapping("/delete")
    @RamResource(action = "pay:mchPayPassage:delete", name = "删除商户支付通道配置", type = ActionType.WRITE)
    public Resp<?> delete(@RequestParam("id") Long id) {
        if (!mchPayPassageService.removeById(id)) {
            throw new BizException("记录不存在");
        }
        return Resp.ok();
    }

    @PostMapping("/saveOrUpdate")
    @RamResource(action = "pay:mchPayPassage:delete", name = "删除商户支付通道配置", type = ActionType.WRITE)
    public Resp<?> saveOrUpdate(@RequestBody MchPayPassageRQ req) {
        mchPayPassageService.saveOrUpdatePayPassage(req);
        return Resp.ok();
    }
}
